//
//  GDCollectionWaterView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/1/31.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "GDCollectionWaterView.h"
#import "GDArmImageCollectionViewCell.h"
static NSString * const reuseIdentifier = @"Cell";


@interface GDCollectionWaterView()<UICollectionViewDelegate, UICollectionViewDataSource>

@end

@implementation GDCollectionWaterView

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    if(self = [super initWithFrame:frame collectionViewLayout:layout]){
        [self registerClass:[GDArmImageCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
        self.dataSource = self;
        self.delegate = self;
        self.imageDataArray = [NSMutableArray array];
        self.cacheSizes = [NSMutableArray array];
        self.showsVerticalScrollIndicator = NO;
    }
    return self;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.imageDataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    GDArmImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.model = self.imageDataArray[indexPath.item];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if([self.GDdelegate respondsToSelector:@selector(selectIndexWithIndexPath:)]){
        [self.GDdelegate selectIndexWithIndexPath:indexPath.item];
    }
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    CGFloat width = 1;
    return UIEdgeInsetsMake(width, 0, 0, 0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    CGFloat width = 1.8;
    return width;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    CGFloat width = 1.25;
    return width;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGSize size = [(NSNumber *)[self.cacheSizes
                                objectAtIndex:indexPath.row] CGSizeValue];
    return CGSizeMake(collectionView.frame.size.width * size.width - 1, collectionView.frame.size.width * size.height - 1);
}


@end
